package com.siteseat.crudeq.broker.filter;

import java.util.Iterator;

import com.siteseat.crudeq.broker.transport.BrokerSession;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;

/**
 *
 */
public class FilterChain {

  private Iterator<Filter> current;

  /**
   * @param current
   */
  public FilterChain( Iterator<Filter> current ) {
    this.current = current;
  }

  /**
   * @param req
   * @param resp
   * @return
   * @throws Exception
   */
  public void execute( FilterChain chain, BrokerSession session, byte reqId, Channel channel,
          ChannelBuffer channelBuffer ) throws Exception {

    if( hasNext() ) {
      Filter f = this.current.next();
      f.execute( chain, session, reqId, channel, channelBuffer );
    }
  }

  /**
   * @return
   */
  public boolean hasNext() {
    return this.current.hasNext();
  }
}
